lastlog -u milad
lastlog | tail -3
lastlog | grep -vi never
# last --help
last --since "5 min ago" -n 1
last | tail -6 | tac | tail -4
last reboot -n5
sudo lastb
milad tty1 Fri Feb 24 12:26 - 12:26 (00:00)
ls /var/log/*tmp -1
whatis dmesg
dmesg -l err -H # Level, Human readable
cat /var/log/dmesg # Until system boot
pgrep syslog -a
# Lets see what syslog is
apt-cache show rsyslog | grep -i desc -A14 -m1 | cat
ls /var/log | egrep -v "gz|.1" | tr "\n" " "
apt auth.log btmp dmesg kern.log lastlog wtmp syslog
tail /var/log/auth.log | grep sudo | head -1
# lets see how rsyslog manages these files
# facilities 0.kern
# priority 0 emerg
# /identifier sudo/
vim /etc/rsyslog.d/50-default.conf
logger -p mail.err "Milad is not able to send mail"
tail -1 /var/log/mail.err
whatis logrotate
logrotate /etc/logrotate.conf
/var/log/test.log
{
rotate 4
weekly
missingok
notifempty
compress
}
When used alone, every journal entry that is in the system will be displayed.
whatis journalctl
# remember our mail message log?
# logger -p mail.err "Milad is not able to send mail"
journalctl SYSLOG_FACILITY=2 -n1
journalctl -n 3
journalctl -n 2 -x # extra explaination (catalog)
# vim /etc/systemd/journald.conf
[Journal]
Storage=persistent
man 5 journald.conf
/Storage
"volatile", "persistent", "auto"
"persistent", data will be stored preferably on disk
journalctl --list-boots
journalctl -b # Last boot
journalctl -b 8dcd6ce7c4f141eb9c52dd88b71ac0d6 -n1
# journalctl -b 0
journalctl --since 16:02 --until 16:07
journalctl --since "2017-02-28 16:05"
Available words: "yesterday", "today", "tomorrow", or "now"
journalctl --since yesterday
journalctl --since 01:00 --until "5 hour ago"
journalctl -u virtualbox.service -n1
journalctl _SYSTEMD_UNIT=virtualbox.service --no-full -n1
systemctl status dbus
journalctl -u dbus -n --no-full
journalctl -u dbus.service --since yesterday -n3 -b0
journalctl -t dbus -n3 --no-full # syslog identifier (look at systemd message at above example)
man systemd.journal-fields
journalctl -N | grep "^_" | tail -10
journalctl _UID=`id -u privoxy`
Available values for a given journal field:
journalctl -F _TRANSPORT
# transport = How the entry was received by the journal service.
journalctl _TRANSPORT=kernel | head -3 | tail -2
journalctl -F SYSLOG_IDENTIFIER -n10
journalctl -t smartd -r -n1
journalctl -N | grep -i fac
journalctl -F SYSLOG_FACILITY | tr '\n' ' '
kernel ring buffer (dmesg)
journalctl -k | wc -l
journalctl --dmesg | wc -l
dmesg | wc -l
journalctl -k -b -3
journalctl SYSLOG_FACILITY=0 -n2
journalctl `which NetworkManager` -n1
journalctl -u NetworkManager.service | wc -l
journalctl `which NetworkManager` | wc -l
journalctl -p [tab][tab]
0: emerg : System is unusable
1: alert : Should be corrected immediately
2: crit : Critical conditions
3: err : Error conditions
4: warning : May indicate that an error will occur if action is not taken.
5: notice : Events that are unusual, but not error conditions.
6: info : Normal operational messages that require no action.
7: debug : Information useful to developers for debugging the application.
journalctl -p 1 -n1 # -p emerg
journalctl -p crit -o json-pretty # [tab-tab]
journalctl -k -f # following like tail -f
journalctl --disk-usage
sudo journalctl --vacuum-size=5M
sudo journalctl --vacuum-time=2months
Referenses:
LFCS & RHCSA
man dmsg
man journalctl
man 5 journald.conf
man systemd.journal-fields
http://www.linfo.org/dmesg.html
https://wiki.archlinux.org/index.php/Systemd
https://help.ubuntu.com/community/LinuxLogFiles
https://tools.ietf.org/html/rfc5424#section-6.2.1
https://www.digitalocean.com/community/tutorials/how-to-use-journalctl-to-view-and-manipulate-systemd-logs
ipynb
format: https://github.com/ravexina/linux-notes. html
exports of project available at: https://ravexina.github.io/linux-notes.Linux Notes by Milad As (Ravexina) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.